﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SuperSocket.ClientEngine;
using SuperSocket.SocketBase;

namespace SuperSoketDemo_One
{
    public partial class Form1 : Form
    {
        private SSClient _ssc = new SSClient("10.23.5.233", 2000);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _ssc.Connect();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string loginCmd = "ECHO";
            string str = "";
            using (FileStream fs = new FileStream(@"json1.json", FileMode.Open))
            {
                StreamReader fileStream = new StreamReader(fs);
                string line;
                while ((line = fileStream.ReadLine()) != null)
                {
                    str += line;
                }
            }
            //上面的代码没有意义，只是将Json文件的内容加载到字符串中
            JObject jObject = new JObject();        //新建 操作对象
            List<AccessTokenModel> a = JsonConvert.DeserializeObject<List<AccessTokenModel>>(str);
            //byte[] data = Encoding.Default.GetBytes(loginCmd);
            _ssc.str.Clear();
            _ssc.reint = 0;
            _ssc.SendCommand(loginCmd, str);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (_ssc.str.ToString().IndexOf("*end*") > -1)
            {
                MessageBox.Show("接收完了： " + _ssc.reint);
                _ssc.str.Clear();
                _ssc.reint = 0;
            }
            else
            {
                MessageBox.Show("还没接收完");
            }
        }
    }
}
